{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>角色列表</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        <a href="{:url('groupAdd')}" class="layui-btn layui-btn-sm">{:lang('add')}角色</a>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}

<script type="text/html" id="action">
    <a href="{:url('groupAccess')}?id={{d.position_id}}" class="layui-btn layui-btn-xs layui-btn-normal">配置权限</a>
    <button  data-id="{{d.position_id}}" class="layui-btn layui-btn-xs edit-timu layui-btn-normal">配置考核项</button>
    <a href="{:url('groupEdit')}?id={{d.position_id}}" class="layui-btn layui-btn-warm layui-btn-xs">{:lang('edit')}</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.position_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script>

    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        table.render({
            elem: '#list',
            url: '{:url("adminGroup")}',
            method:'post',
            cols: [[
                {field:'position_id', title: '{:lang("id")}',width:80, fixed: true,sort: true},
                {field:'position_name', title: '角色名称', width:180},
                {field:'create_time', title: '添加时间', width:200,sort: true},
                {field:'update_time', title: '更新时间', width:200,sort: true},
                {field: 'status', align: 'center', title: '启用状态', width: 100, toolbar: '#status'},
                {width:260, align:'center',toolbar:'#action'}
            ]]
        });

        form.on('switch(status)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var position_id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post('{:url("groupState")}',{'id':position_id,'status':status},function (res) {
                layer.close(loading);
                if (res.code==1) {
                    layer.msg(res.msg,{time:1000,icon:1});
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        // 配置考核项
        $(document).on('click','.edit-timu',function () {
            var id=$(this).attr('data-id');
            layer.open({
                type:2,
                title: '配置考核项',
                shadeClose:true,
                shade:0.3,
                area:['80%','80%'],
                content: '{:url("groupAssess")}?position_id='+id
            });
        });
        table.on('tool(list)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定要删除该角色吗？', function(index){
                    loading =layer.load(1, {shade: [0.1,'#fff']});
                    $.post("{:url('groupDel')}",{id:data.position_id},function(res){
                        layer.close(loading);
                        layer.close(index);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }
        });
    });
</script>
</body>
</html>